import axiosInstance from '@/api/axiosRequest';
import {Res} from '@/api/base';
import { Message } from '@arco-design/web-vue';
import {getToken} from '@/utils/auth';
import axios from 'axios';
import { baseURL } from '@/api/base';


const axiosInstance2 = axios.create({
  baseURL: baseURL,
  timeout: 20000
});

export async function postRequest(url:string,params: any) {
  let res = await axiosInstance.post<Res>(url,params);
  if(res && res.data){
    if (res.data.code == 200){
      if(res.data.result == null){
        res.data.result = {};
      }
      return res.data.result;
    }else{
      Message.error(res.data.message);
      return null;
    }
  }else{
    Message.error(res.data.message);
  }
  return null;
}


export async function postBase(url:string,params: any) {
  let res = await axiosInstance.post<Res>(url,params);
  if(res && res.data){
    return res.data;
  }else{
    Message.error(res.data.message);
  }
  return null;
}

// ..下载文件
export function toLeadFile(url:string,data:any) {
  return axiosInstance.post<Res>(url,data,{
    headers:{
      'Authorization': getToken() || '',
      "Content-Type": "multipart/form-data",
    }
  })
}

//上传文件 上传formData
export function uploadFileRequest(url:string,data:FormData){
  return axios.post<Res>(baseURL+""+url, data, {
    headers:{
      'Authorization': getToken() || '',
      'Content-Type': 'multipart/form-data'
    }
  })
}
